/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var preorderTraversal = function (root) {
  let result = []
  let preOrder = (node, res) => {
    if (node === null) return
    let { val, left, right } = node
    res.push(val);
    preOrder(left, res)
    preOrder(right, res)
  }
  preOrder(root, result)
  return result
  return !root? []:[].concat([root.val]).concat(preorderTraversal(root.left)).concat(preorderTraversal(root.right))
};